package com.mxpio.webapp.config;

import com.mxpio.webapp.socket.WebSocketInterceptor;
import com.mxpio.webapp.socket.handler.WebSshHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * websocket配置
 *
 * @author: Cheng
 * @date: 2022/11/12
 */
@Configuration
@EnableWebSocket
public class WebSshSocketConfig implements WebSocketConfigurer {
    private final WebSocketInterceptor webSocketInterceptor;

    public WebSshSocketConfig(WebSocketInterceptor webSocketInterceptor) {
        this.webSocketInterceptor = webSocketInterceptor;
    }


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new WebSshHandler(), "/socket/ssh")
                .addInterceptors(webSocketInterceptor).setAllowedOrigins("*");
    }
}
